"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var axios_1 = __importDefault(require("axios"));
var ant_design_vue_1 = require("ant-design-vue");
// 创建 Axios 实例
var myAxios = axios_1.default.create({
    baseURL: 'http://localhost:8123',
    timeout: 60000,
    withCredentials: true, //请求时携带cookie
});
// 全局请求拦截器
myAxios.interceptors.request.use(function (config) {
    // console.log('全局请求拦截:',config);
    // Do something before request is sent
    return config;
}, function (error) {
    // Do something with request error
    return Promise.reject(error);
});
// 全局响应拦截器
myAxios.interceptors.response.use(function (response) {
    // console.log('全局拦截响应:',response);
    var data = response.data;
    // 未登录
    if (data.code === 40100) {
        // 不是获取用户信息的请求，并且用户目前不是已经在用户登录页面，则跳转到登录页面
        if (!response.request.responseURL.includes('user/get/login') &&
            !window.location.pathname.includes('/user/login')) {
            ant_design_vue_1.message.warning('请先登录');
            window.location.href = "/user/login?redirect=".concat(window.location.href);
        }
    }
    return response;
}, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
});
exports.default = myAxios;
